package com.lcz.web;

import com.lcz.bean.Grade;
import com.lcz.bean.Student;
import com.lcz.service.GradeService;
import com.lcz.service.StudentService;
import com.lcz.service.impl.GradeServiceImpl;
import com.lcz.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/Educational/student/FindbyIdServlet")
public class FindByIdServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接收参数
        String stuid = req.getParameter("sid");
        //2.调用Service
        StudentService studentService = new StudentServiceImpl();
        Student student = studentService.findById(stuid);
        //3.查询年级列表
        GradeService gradeService = new GradeServiceImpl();
        List<Grade> list = gradeService.getGrade();

        req.setAttribute("list",list);
        req.setAttribute("stu",student);
        req.getRequestDispatcher("edit.jsp").forward(req,resp);
    }
}
